home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip0493.zip / X00API.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  12KB  |  450 lines

  1. /*
  2.  *   X00API.C: X00 FOSSIL driver
  3.  *   
  4.  *   Created by R.F. Pels.
  5.  *   modified by Bob Stout
  6.  *   Placed in the public domain.
  7.  */
  8.  
  9. /* FOSSIL call codes */
  10.  
  11. #define SET_BAUDRATE         0x0000
  12. #define TX_CHAR              0x0100
  13. #define RX_CHAR              0x0200
  14. #define STATUS               0x0300
  15. #define INITIALIZE           0x0400
  16. #define DEINITIALIZE         0x0500
  17. #define RAISE_DTR            0x0600
  18. #define LOWER_DTR            0x0601
  19. #define GET_SYS_INFO         0x0700
  20. #define FLUSH_OUTPUT         0x0800
  21. #define PURGE_OUTPUT         0x0900
  22. #define PURGE_INPUT          0x0A00
  23. #define TX_CHAR_NOWAIT       0x0B00
  24. #define PEEK_AHEAD_INPUT     0x0C00
  25. #define PEEK_AHEAD_KBD       0x0D00
  26. #define READ_KBD             0x0E00
  27. #define FLOW_CONTROL         0x0F00
  28. #define CTLC_CTLK_CHECK      0x1000
  29. #define SET_CUP              0x1100
  30. #define GET_CUP              0x1200
  31. #define WRITE_ANSI_CHAR      0x1300
  32. #define ENABLE_WATCHDOG      0x1401
  33. #define DISABLE_WATCHDOG     0x1400
  34. #define WRITE_BIOS_CHAR      0x1500
  35. #define INSERT_TICK_FUNC     0x1601
  36. #define DELETE_TICK_FUNC     0x1600
  37. #define BOOT_MACHINE         0x1700
  38. #define READ_BLOCK           0x1800
  39. #define WRITE_BLOCK          0x1900
  40. #define START_BREAK_SIGNAL   0x1A01
  41. #define STOP_BREAK_SIGNAL    0x1A00
  42. #define GET_DRIVER_INFO      0x1B00
  43. #define INSTALL_APPENDAGE    0x7e00
  44. #define REMOVE_APPENDAGE     0x7f00
  45.  
  46.  
  47. #include "x00api.h"
  48. #include <dos.h>
  49.  
  50. static union  REGS  x00regs;
  51. static struct SREGS x00sregs;
  52. int                 x00error = 0;
  53.  
  54. #if __cplusplus
  55.  extern "C" {
  56. #endif
  57.  
  58. #ifdef __TURBOC__
  59.  #define PEEK(s,o) peek(s,o)
  60. #else /* MSC or ZTC */
  61.  #define PEEK(s,o) *((unsigned _far *)(MK_FP((s),(o))))
  62. #endif
  63.  
  64. #ifndef MK_FP
  65.  #define MK_FP(seg,offset) \
  66.         ((void _far *)(((unsigned long)(seg)<<16) | (unsigned)(offset)))
  67. #endif
  68.  
  69. unsigned int  x00_detect(void)
  70. {
  71.         unsigned int segofx00;
  72.         unsigned int ofsofx00;
  73.         
  74.         /* Peek in interrupt vector table for start of FOSSIL */
  75.  
  76.         ofsofx00 = PEEK(0, 0x14 * 4);
  77.         segofx00 = PEEK(0, (0x14 * 4) + 2);
  78.         
  79.         /* Peek in start of FOSSIL + 6 */
  80.  
  81.         return (PEEK(segofx00, ofsofx00 + 6));
  82. }
  83.  
  84. FOSSILSTATUS  x00_set(unsigned char set, PORT port)
  85. {
  86.         FOSSILSTATUS retval;
  87.         
  88.         x00regs.x.ax = SET_BAUDRATE | set;
  89.         x00regs.x.dx = port;
  90.         int86(0x14, &x00regs, &x00regs);
  91.         retval.statusword = x00regs.x.ax;
  92.         return retval;
  93. }
  94.  
  95. FOSSILSTATUS  x00_tx_char(unsigned char c, PORT port)
  96. {
  97.         FOSSILSTATUS retval;
  98.         
  99.         x00regs.x.ax = TX_CHAR | c;
  100.         x00regs.x.dx = port;
  101.         int86(0x14, &x00regs, &x00regs);
  102.         retval.statusword = x00regs.x.ax;
  103.         return retval;
  104. }
  105.  
  106. unsigned char  x00_rx_char(PORT port)
  107. {
  108.         x00regs.x.ax = RX_CHAR;
  109.         x00regs.x.dx = port;
  110.         int86(0x14, &x00regs, &x00regs);
  111.         return (unsigned char)(x00regs.x.ax & 0xff);
  112. }
  113.  
  114. FOSSILSTATUS  x00_status(PORT port)
  115. {
  116.         FOSSILSTATUS retval;
  117.         
  118.         x00regs.x.ax = STATUS;
  119.         x00regs.x.dx = port;
  120.         int86(0x14, &x00regs, &x00regs);
  121.         retval.statusword = x00regs.x.ax;
  122.         return retval;
  123. }
  124.  
  125. FOSSILINIT    x00_init(PORT port, unsigned char far *ctlc_flagbyte)
  126. {
  127.         FOSSILINIT retval;
  128.         
  129.         x00regs.x.ax = INITIALIZE;
  130.         if (ctlc_flagbyte != (unsigned char far *)0)
  131.         {
  132.                 x00regs.x.dx = 0x00ff;
  133.                 x00regs.x.bx = 0x4F50;
  134.                 segread(&x00sregs);
  135.                 x00sregs.es  = FP_SEG(ctlc_flagbyte);
  136.                 x00regs.x.cx = FP_OFF(ctlc_flagbyte);
  137.         }
  138.         else
  139.         {
  140.                 x00regs.x.bx = 0x0000; /* in any case _NOT_ 0x4f50 */
  141.                 x00regs.x.dx = port;
  142.         }
  143.         int86x(0x14, &x00regs, &x00regs, &x00sregs);
  144.         retval.result       = x00regs.x.ax;
  145.         retval.max_function = (unsigned char)(x00regs.x.bx & 0xff);
  146.         retval.revision     = (unsigned char)(x00regs.x.bx >> 8);
  147.         return retval;
  148. }
  149.  
  150. void          x00_deinit(PORT port)
  151. {
  152.         x00regs.x.ax = DEINITIALIZE;
  153.         x00regs.x.dx = port;
  154.         int86(0x14, &x00regs, &x00regs);
  155. }
  156.  
  157. unsigned int  x00_raise_dtr(PORT port)
  158. {
  159.         unsigned int retval;
  160.         
  161.         x00regs.x.ax = RAISE_DTR;
  162.         x00regs.x.dx = port;
  163.         int86(0x14, &x00regs, &x00regs);
  164.         if ((x00regs.x.ax & 0x0001) == 1)
  165.         {
  166.                 retval = X00_DTR_HIGH;
  167.         }
  168.         else    retval = X00_DTR_LOW;
  169.         return retval;
  170. }
  171.  
  172. unsigned int  x00_lower_dtr(PORT port)
  173. {
  174.         unsigned int retval;
  175.         
  176.         x00regs.x.ax = LOWER_DTR;
  177.         x00regs.x.dx = port;
  178.         int86(0x14, &x00regs, &x00regs);
  179.         if ((x00regs.x.ax & 0x0001) == 1)
  180.         {
  181.                 retval = X00_DTR_HIGH;
  182.         }
  183.         else    retval = X00_DTR_LOW;
  184.         return retval;
  185. }
  186.  
  187. FOSSILSYSINFO x00_sysinfo(void)
  188. {
  189.         FOSSILSYSINFO retval;
  190.         
  191.         x00regs.x.ax = GET_SYS_INFO;
  192.         int86(0x14, &x00regs, &x00regs);
  193.         retval.tick_number        = (unsigned char)(x00regs.x.ax & 0xff);
  194.         retval.ticks_per_second   = (unsigned char)(x00regs.x.ax >> 8);
  195.         retval.approx_ms_per_tick = x00regs.x.dx;
  196.         return retval;
  197. }
  198.  
  199. void          x00_flush_output(PORT port)
  200. {
  201.         x00regs.x.ax = FLUSH_OUTPUT;
  202.         x00regs.x.dx = port;
  203.         int86(0x14, &x00regs, &x00regs);
  204. }
  205.  
  206. void          x00_purge_output(PORT port)
  207. {
  208.         x00regs.x.ax = PURGE_OUTPUT;
  209.         x00regs.x.dx = port;
  210.         int86(0x14, &x00regs, &x00regs);
  211. }
  212.  
  213. void          x00_purge_input(PORT port)
  214. {
  215.         x00regs.x.ax = PURGE_INPUT;
  216.         x00regs.x.dx = port;
  217.         int86(0x14, &x00regs, &x00regs);
  218. }
  219.  
  220. unsigned int  x00_tx_char_nowait(unsigned char c, PORT port)
  221. {
  222.         unsigned int retval;
  223.         
  224.         x00regs.x.ax = TX_CHAR_NOWAIT | c;
  225.         x00regs.x.dx = port;
  226.         int86(0x14, &x00regs, &x00regs);
  227.         if ((x00regs.x.ax & 0x0001) == 1)
  228.         {
  229.                 retval = X00_OK;
  230.         }
  231.         else    retval = X00_CHAR_NOT_SENT;
  232.         return retval;
  233. }
  234.  
  235. unsigned int  x00_peek_ahead_input(PORT port)
  236. {
  237.         x00regs.x.ax = PEEK_AHEAD_INPUT;
  238.         x00regs.x.dx = port;
  239.         int86(0x14, &x00regs, &x00regs);
  240.         return x00regs.x.ax;
  241. }
  242.  
  243. unsigned int   x00_peek_ahead_kbd(void)
  244. {
  245.         x00regs.x.ax = PEEK_AHEAD_KBD;
  246.         int86(0x14, &x00regs, &x00regs);
  247.         return x00regs.x.ax;
  248. }
  249.  
  250. unsigned int  x00_read_kbd(void)
  251. {
  252.         x00regs.x.ax = READ_KBD;
  253.         int86(0x14, &x00regs, &x00regs);
  254.         return x00regs.x.ax;
  255. }
  256.  
  257. void          x00_flow_control(FOSSILFLOWCTRL f, PORT port)
  258. {
  259.         x00regs.x.ax = FLOW_CONTROL | 0xf0 | f.flowword;
  260.         x00regs.x.dx = port;
  261.         int86(0x14, &x00regs, &x00regs);
  262. }
  263.  
  264. unsigned int  x00_ctlc_ctlk_check(FOSSILCTLCCTLK c, PORT port)
  265. {
  266.         x00regs.x.ax = CTLC_CTLK_CHECK | c.checkword;
  267.         x00regs.x.dx = port;
  268.         int86(0x14, &x00regs, &x00regs);
  269.         return x00regs.x.ax;
  270. }
  271.  
  272. void          x00_set_cup(unsigned char row, unsigned char col)
  273. {
  274.         x00regs.x.ax = SET_CUP;
  275.         x00regs.x.dx = (row << 8) | col;
  276.         int86(0x14, &x00regs, &x00regs);
  277. }
  278.  
  279. void          x00_get_cup(unsigned char *row, unsigned char *col)
  280. {
  281.         x00regs.x.ax = GET_CUP;
  282.         int86(0x14, &x00regs, &x00regs);
  283.         *col = (unsigned char)(x00regs.x.dx & 0xff);
  284.         *row = (unsigned char)(x00regs.x.dx >> 8);
  285. }
  286.  
  287. void          x00_write_ANSI_char(unsigned char c)
  288. {
  289.         x00regs.x.ax = WRITE_ANSI_CHAR | c;
  290.         int86(0x14, &x00regs, &x00regs);
  291. }
  292.  
  293. void          x00_enable_watchdog(PORT port)
  294. {
  295.         x00regs.x.ax = ENABLE_WATCHDOG;
  296.         x00regs.x.dx = port;
  297.         int86(0x14, &x00regs, &x00regs);
  298. }
  299.  
  300. void          x00_disable_watchdog(PORT port)
  301. {
  302.         x00regs.x.ax = DISABLE_WATCHDOG;
  303.         x00regs.x.dx = port;
  304.         int86(0x14, &x00regs, &x00regs);
  305. }
  306.  
  307. void          x00_write_BIOS_char(unsigned char c)
  308. {
  309.         x00regs.x.ax = WRITE_BIOS_CHAR | c;
  310.         int86(0x14, &x00regs, &x00regs);
  311. }
  312.  
  313. unsigned int  x00_insert_tick_func(void (far *tickfunc)())
  314. {
  315.         unsigned int retval;
  316.         
  317.         x00regs.x.ax = INSERT_TICK_FUNC;
  318.         x00regs.x.dx = FP_OFF(tickfunc);
  319.         segread(&x00sregs);
  320.         x00sregs.es  = FP_SEG(tickfunc);
  321.         int86x(0x14, &x00regs, &x00regs, &x00sregs);
  322.         if (x00regs.x.ax == 0x0000)
  323.         {
  324.                 retval = X00_OK;
  325.         }
  326.         else    retval = X00_INS_TICK;
  327.         return retval;
  328. }
  329.  
  330. unsigned int  x00_delete_tick_func(void (far *tickfunc)())
  331. {
  332.         unsigned int retval;
  333.         
  334.         x00regs.x.ax = DELETE_TICK_FUNC;
  335.         x00regs.x.dx = FP_OFF(tickfunc);
  336.         segread(&x00sregs);
  337.         x00sregs.es  = FP_SEG(tickfunc);
  338.         int86x(0x14, &x00regs, &x00regs, &x00sregs);
  339.         if (x00regs.x.ax == 0x0000)
  340.         {
  341.                 retval = X00_OK;
  342.         }
  343.         else    retval = X00_DEL_TICK;
  344.         return retval;
  345. }
  346.  
  347. void          x00_boot_machine(unsigned int boottype)
  348. {
  349.         x00regs.x.ax = BOOT_MACHINE | (boottype & 0x0001);
  350.         int86(0x14, &x00regs, &x00regs);
  351. }
  352.  
  353. unsigned int  x00_read_block(unsigned int count, void far *buf, PORT port)
  354. {
  355.         x00regs.x.ax = READ_BLOCK;
  356.         x00regs.x.cx = count;
  357.         x00regs.x.dx = port;
  358.         segread(&x00sregs);
  359.         x00sregs.es  = FP_SEG(buf);
  360.         x00regs.x.di = FP_OFF(buf);
  361.         int86x(0x14, &x00regs, &x00regs, &x00sregs);
  362.         return x00regs.x.ax;
  363. }
  364.  
  365. unsigned int  x00_write_block(unsigned int count, void far *buf, PORT port)
  366. {
  367.         x00regs.x.ax = WRITE_BLOCK;
  368.         x00regs.x.cx = count;
  369.         x00regs.x.dx = port;
  370.         segread(&x00sregs);
  371.         x00sregs.es  = FP_SEG(buf);
  372.         x00regs.x.di = FP_OFF(buf);
  373.         int86x(0x14, &x00regs, &x00regs, &x00sregs);
  374.         return x00regs.x.ax;
  375. }
  376.  
  377. void          x00_start_break_signal(PORT port)
  378. {
  379.         x00regs.x.ax = START_BREAK_SIGNAL;
  380.         x00regs.x.dx = port;
  381.         int86(0x14, &x00regs, &x00regs);
  382. }
  383.  
  384. void          x00_stop_break_signal(PORT port)
  385. {
  386.         x00regs.x.ax = STOP_BREAK_SIGNAL;
  387.         x00regs.x.dx = port;
  388.         int86(0x14, &x00regs, &x00regs);
  389. }
  390.  
  391. unsigned int  x00_get_driverinfo(void far *buf, PORT port)
  392. {
  393.         x00regs.x.ax = GET_DRIVER_INFO;
  394.         x00regs.x.cx = sizeof(FOSSILINFO);
  395.         segread(&x00sregs);
  396.         x00sregs.es  = FP_SEG(buf);
  397.         x00regs.x.di = FP_OFF(buf);
  398.         x00regs.x.dx = port;
  399.         int86x(0x14, &x00regs, &x00regs, &x00sregs);
  400.         return x00regs.x.ax;
  401. }
  402.  
  403. unsigned int  x00_install_appendage(unsigned char appcode,
  404.                                               void (far *appfunc)())
  405. {
  406.         unsigned int retval;
  407.         
  408.         x00regs.x.ax = INSTALL_APPENDAGE | appcode;
  409.         segread(&x00sregs);
  410.         x00sregs.es  = FP_SEG(appfunc);
  411.         x00regs.x.dx = FP_OFF(appfunc);
  412.         int86x(0x14, &x00regs, &x00regs, &x00sregs);
  413.         if (x00regs.x.ax == X00_PRESENT)
  414.         {
  415.                 if ((x00regs.x.bx & 0xff00) == 1)
  416.                 {
  417.                         retval = X00_OK;
  418.                 }
  419.                 else    retval = X00_INS_APP;
  420.         }
  421.         else    retval = X00_NOT_HERE;
  422.         return retval;
  423. }
  424.  
  425. unsigned int  x00_remove_appendage(unsigned char appcode,
  426.                                              void (far *appfunc)())
  427. {
  428.         unsigned int retval;
  429.         
  430.         x00regs.x.ax = REMOVE_APPENDAGE | appcode;
  431.         segread(&x00sregs);
  432.         x00sregs.es  = FP_SEG(appfunc);
  433.         x00regs.x.dx = FP_OFF(appfunc);
  434.         int86x(0x14, &x00regs, &x00regs, &x00sregs);
  435.         if (x00regs.x.ax == X00_PRESENT)
  436.         {
  437.                 if ((x00regs.x.bx & 0xff00) == 1)
  438.                 {
  439.                         retval = X00_OK;
  440.                 }
  441.                 else    retval = X00_REM_APP;
  442.         }
  443.         else    retval = X00_NOT_HERE;
  444.         return retval;
  445. }
  446.  
  447. #if __cplusplus
  448.  }
  449. #endif
  450.